<?php
/**
 *    配置账号信息
 */

use think\facade\Db;

class WxSendApi
{
    /**配送动态通知用户骑手接单
     * @param Request $request
     * @return \think\response\Json
     */
    public function send_Template_dynamic($user_id,$send_id, $data)
    {
        require_once '../sdk/WxpayAPI/lib/WxPay.Config.php';
        $appid = \WxPayConfig::APPID;
        $secret = \WxPayConfig::APPSECRET;
        //获取token
        $fileName = '../sdk/WxpayAPI/wechat_token.txt';
        $token_data = file_get_contents($fileName);
        $time = 7200;
        if (!empty($token_data)) {
            $token_data = json_decode($token_data, true);
            $time = time() - $token_data['time'];
        }
        if ($time > 3600) {
            $token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
            $token_res = $this->https_request($token_url);
            $token_res = json_decode($token_res, true);
            $token = $token_res['access_token'];
            $date = array(
                'time' => time(),
                'token' => $token
            );
            $res = file_put_contents($fileName, json_encode($date));
        } else {
            $token = $token_data['token'];
        }
        $name = '';
        $user = Db::table('eb_user')->where('id', $user_id)->find();
        $order_detail = Db::table('eb_order_detail')->where('order_id', $data['id'])->select()->toArray();
        foreach ($order_detail as $key => &$value) {
            $value1 = Db::table('eb_goods')->where('id', $value['goods_id'])->find();
            if ($value1['name']) {
                $name .= $value1['name'] . ' ';
            }
        }
        $store = Db::table('eb_store')->where('id', $data['store_id'])->find();
        $send = Db::table('eb_user')->where('id', $send_id)->find();
        $dats = [
            "touser" => $user['openid'], //对方的openid，前一步获取
            "template_id" => "xox-JiAhVxrQoU6WLvj6d8aGtElVpWAvfBmUKP1ROeg", //模板id
            "data" => [
                "first" => [
                    "value" => "尊敬的用户， 您好：", //自定义参数
                    "color" => '#D0AEF4'//自定义颜色
                ],
                "Content1" => [
                    "value" => '您购买的商品已经被骑手接单，请您留意电话哦！！', //自定义参数
                    "color" => '#2E2E2E'//自定义颜色
                ],
                "Good" => [
                    "value" => $name, //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "distributors" => [
                    "value" => "如有疑问，请联系:" . $store['shop_name'] . ',联系电话：' . $store['bank_phone'], //自定义参数
                    "color" => '#9423FF'//自定义颜色
                ],
                "name" => [
                    "value" => $send['name'].'，骑手电话：'.$send['phone'], //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "menu" => [//收费标准
                    "value" => "若对收费有疑问，请联系商家解决！", //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "remark" => [
                    "value" => "感谢您的光顾，祝您用餐愉快！！", //自定义参数
                    "color" => '#336600'//自定义颜色
                ],
            ]
        ];
        $msgurl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $token; // 发送模板消息接口
        $data = json_encode($dats, JSON_UNESCAPED_UNICODE);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $msgurl);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }

    /**配送动态通知用户商品送达
     * @param Request $request
     * @return \think\response\Json
     */
    public function send_Template_arrive($user_id, $data)
    {
        require_once '../sdk/WxpayAPI/lib/WxPay.Config.php';
        $appid = \WxPayConfig::APPID;
        $secret = \WxPayConfig::APPSECRET;
        //获取token
        $fileName = '../sdk/WxpayAPI/wechat_token.txt';
        $token_data = file_get_contents($fileName);
        $time = 7200;
        if (!empty($token_data)) {
            $token_data = json_decode($token_data, true);
            $time = time() - $token_data['time'];
        }
        if ($time > 3600) {
            $token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
            $token_res = $this->https_request($token_url);
            $token_res = json_decode($token_res, true);
            $token = $token_res['access_token'];
            $date = array(
                'time' => time(),
                'token' => $token
            );
            $res = file_put_contents($fileName, json_encode($date));
        } else {
            $token = $token_data['token'];
        }
        $name = '';
        $user = Db::table('eb_user')->where('id', $user_id)->find();
        $order_detail = Db::table('eb_order_detail')->where('order_id', $data['id'])->select()->toArray();
        foreach ($order_detail as $key => &$value) {
            $value1 = Db::table('eb_goods')->where('id', $value['goods_id'])->find();
            if ($value1['name']) {
                $name .= $value1['name'] . ' ';
            }
        }
        $store = Db::table('eb_store')->where('id', $data['store_id'])->find();
        $send = Db::table('eb_user')->where('id', $data['send_id'])->find();
        $dats = [
            "touser" => $user['openid'], //对方的openid，前一步获取
            "template_id" => "xox-JiAhVxrQoU6WLvj6d8aGtElVpWAvfBmUKP1ROeg", //模板id
            "data" => [
                "first" => [
                    "value" => "尊敬的用户， 您好：", //自定义参数
                    "color" => '#D0AEF4'//自定义颜色
                ],
                "Content1" => [
                    "value" => '商品即将送达，请留意电话，注意查收，确保商品完整无误，记得五星好评哦，祝您用餐愉快！！', //自定义参数
                    "color" => '#2E2E2E'//自定义颜色
                ],
                "Good" => [
                    "value" => $name, //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "distributors" => [
                    "value" => "如有疑问，请联系:" . $store['shop_name'] . ',联系电话：' . $store['bank_phone'], //自定义参数
                    "color" => '#9423FF'//自定义颜色
                ],
                "name" => [
                    "value" => $send['name'].'，骑手电话：'.$send['phone'], //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "menu" => [//收费标准
                    "value" => "若对订单商品有疑问，请尽快联系商家解决,", //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "remark" => [
                    "value" => "感谢您的光顾，祝您用餐愉快，请尽快对订单进行评价哦，若长时间未进行评价，系统默认好评！", //自定义参数
                    "color" => '#336600'//自定义颜色
                ],
            ]
        ];
        $msgurl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $token; // 发送模板消息接口
        $data = json_encode($dats, JSON_UNESCAPED_UNICODE);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $msgurl);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
    /**配送动态骑手有新订单
     * @param Request $request
     * @return \think\response\Json
     */
    public function send_Template_rider($user, $data)
    {
        require_once '../sdk/WxpayAPI/lib/WxPay.Config.php';
        $appid = \WxPayConfig::APPID;
        $secret = \WxPayConfig::APPSECRET;
        //获取token
        $fileName = '../sdk/WxpayAPI/wechat_token.txt';
        $token_data = file_get_contents($fileName);
        $time = 7200;
        if (!empty($token_data)) {
            $token_data = json_decode($token_data, true);
            $time = time() - $token_data['time'];
        }
        if ($time > 3600) {
            $token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
            $token_res = $this->https_request($token_url);
            $token_res = json_decode($token_res, true);
            $token = $token_res['access_token'];
            $date = array(
                'time' => time(),
                'token' => $token
            );
            $res = file_put_contents($fileName, json_encode($date));
        } else {
            $token = $token_data['token'];
        }
        $name = '';
        $order_detail = Db::table('eb_order_detail')->where('order_id', $data['id'])->select()->toArray();
        foreach ($order_detail as $key => &$value) {
            $value1 = Db::table('eb_goods')->where('id', $value['goods_id'])->find();
            if ($value1['name']) {
                $name .= $value1['name'] . ' ';
            }
        }
        $store = Db::table('eb_store')->where('id', $data['store_id'])->find();
        $dats = [
            "touser" => $user['openid'], //对方的openid，前一步获取
            "template_id" => "xox-JiAhVxrQoU6WLvj6d8aGtElVpWAvfBmUKP1ROeg", //模板id
            "data" => [
                "first" => [
                    "value" => "辛勤的".$user['name']."， 您好：", //自定义参数
                    "color" => '#D0AEF4'//自定义颜色
                ],
                "Content1" => [
                    "value" => '您有新的待配送订单，请及时赶往商家配送哦！', //自定义参数
                    "color" => '#2E2E2E'//自定义颜色
                ],
                "Good" => [
                    "value" => $name, //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "distributors" => [
                    "value" => "如有疑问，请联系:" . $store['shop_name'] . ',联系电话：' . $store['bank_phone'], //自定义参数
                    "color" => '#9423FF'//自定义颜色
                ],
//                "name" => [
//                    "value" => $send['name'].'，骑手电话：'.$send['phone'], //自定义参数
//                    "color" => '#173177'//自定义颜色
//                ],
                "menu" => [//收费标准
                    "value" => "若对订单有疑问，请联系商家解决！", //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "remark" => [
                    "value" => "配餐途中注意交通安全，遵守交通规则，注意文明礼貌！！", //自定义参数
                    "color" => '#336600'//自定义颜色
                ],
            ]
        ];
        $msgurl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $token; // 发送模板消息接口
        $data = json_encode($dats, JSON_UNESCAPED_UNICODE);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $msgurl);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
    /**配送动态通知骑手快超时
     * @param Request $request
     * @return \think\response\Json
     */
    public function send_rider_remind($user_id, $data)
    {
        require_once './sdk/WxpayAPI/lib/WxPay.Config.php';
        $appid = \WxPayConfig::APPID;
        $secret = \WxPayConfig::APPSECRET;
        //获取token
        $fileName = './sdk/WxpayAPI/wechat_token.txt';
        $token_data = file_get_contents($fileName);
        $time = 7200;
        if (!empty($token_data)) {
            $token_data = json_decode($token_data, true);
            $time = time() - $token_data['time'];
        }
        if ($time > 3600) {
            $token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
            $token_res = $this->https_request($token_url);
            $token_res = json_decode($token_res, true);
            $token = $token_res['access_token'];
            $date = array(
                'time' => time(),
                'token' => $token
            );
            $res = file_put_contents($fileName, json_encode($date));
        } else {
            $token = $token_data['token'];
        }
        $name = '';
        $order_detail = Db::table('eb_order_detail')->where('order_id', $data['id'])->select()->toArray();
        foreach ($order_detail as $key => &$value) {
            $value1 = Db::table('eb_goods')->where('id', $value['goods_id'])->find();
            if ($value1['name']) {
                $name .= $value1['name'] . ' ';
            }
        }
        $user = Db::table('eb_user')->where('id',$user_id)->find();
        $store = Db::table('eb_store')->where('id', $data['store_id'])->find();
        $dats = [
            "touser" => $user['openid'], //对方的openid，前一步获取
            "template_id" => "xox-JiAhVxrQoU6WLvj6d8aGtElVpWAvfBmUKP1ROeg", //模板id
            "data" => [
                "first" => [
                    "value" => "辛勤的".$user['name']."， 您好：", //自定义参数
                    "color" => '#D0AEF4'//自定义颜色
                ],
                "Content1" => [
                    "value" => '您配送的订单即将超时，请尽快配送哦！', //自定义参数
                    "color" => '#2E2E2E'//自定义颜色
                ],
                "Good" => [
                    "value" => $name, //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "distributors" => [
                    "value" => "如有疑问，请联系:" . $store['shop_name'] . ',联系电话：' . $store['bank_phone'], //自定义参数
                    "color" => '#9423FF'//自定义颜色
                ],
                "name" => [
                    "value" => $user['name'].'，骑手电话：'.$user['phone'], //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "menu" => [//收费标准
                    "value" => "若对订单有疑问，请联系商家解决！", //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "remark" => [
                    "value" => "配餐途中注意交通安全，遵守交通规则，注意文明礼貌！！", //自定义参数
                    "color" => '#336600'//自定义颜色
                ],
            ]
        ];
        $msgurl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $token; // 发送模板消息接口
        $data = json_encode($dats, JSON_UNESCAPED_UNICODE);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $msgurl);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
    /**配送动态通知用户拒绝退款
     * @param Request $request
     * @return \think\response\Json
     */
    public function send_Template_Refuse($user_id, $data)
    {
        require_once '../sdk/WxpayAPI/lib/WxPay.Config.php';
        $appid = \WxPayConfig::APPID;
        $secret = \WxPayConfig::APPSECRET;
        //获取token
        $fileName = '../sdk/WxpayAPI/wechat_token.txt';
        $token_data = file_get_contents($fileName);
        $time = 7200;
        if (!empty($token_data)) {
            $token_data = json_decode($token_data, true);
            $time = time() - $token_data['time'];
        }
        if ($time > 3600) {
            $token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
            $token_res = $this->https_request($token_url);
            $token_res = json_decode($token_res, true);
            $token = $token_res['access_token'];
            $date = array(
                'time' => time(),
                'token' => $token
            );
            $res = file_put_contents($fileName, json_encode($date));
        } else {
            $token = $token_data['token'];
        }
        $name = '';
        $order_detail = Db::table('eb_order_detail')->where('order_id', $data['id'])->select()->toArray();
        foreach ($order_detail as $key => &$value) {
            $value1 = Db::table('eb_goods')->where('id', $value['goods_id'])->find();
            if ($value1['name']) {
                $name .= $value1['name'] . ' ';
            }
        }
        $user = Db::table('eb_user')->where('id', $user_id)->find();
        $store = Db::table('eb_store')->where('id', $data['store_id'])->find();
        $dats = [
            "touser" => $user['openid'], //对方的openid，前一步获取
            "template_id" => "FeHbICOGef84PEWXFkIerrFctLciWFbV2QEycFGab78", //模板id
            "data" => [
                "first" => [
                    "value" => "尊敬的用户---".$user['name']."---， 您好！，您的订单已被商家拒绝退款，如有疑问，请联系商家协商解决。", //自定义参数
                    "color" => '#D0AEF4'//自定义颜色
                ],
                "order_id" => [
                    "value" => $data['order_no'].'----取货码：'.$data['code'], //自定义参数
                    "color" => '#2E2E2E'//自定义颜色
                ],
                "package_id" => [
                    "value" => $data['order_no'], //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "distributors" => [
                    "value" => "如有疑问，请联系:" . $store['shop_name'] . ',联系电话：' . $store['bank_phone'], //自定义参数
                    "color" => '#9423FF'//自定义颜色
                ],
                "remark" => [
                    "value" => "如有疑问，请联系:-----" . $store['shop_name'] . '----,联系电话：' . $store['bank_phone'], //自定义参数
                    "color" => '#336600'//自定义颜色
                ],
            ]
        ];
        $msgurl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $token; // 发送模板消息接口
        $data = json_encode($dats, JSON_UNESCAPED_UNICODE);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $msgurl);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
    /**配送动态通知骑手订单退款
     * @param Request $request
     * @return \think\response\Json
     */
    public function send_Template_Refuse_rider($user_id, $data)
    {
        require_once '../sdk/WxpayAPI/lib/WxPay.Config.php';
        $appid = \WxPayConfig::APPID;
        $secret = \WxPayConfig::APPSECRET;
        //获取token
        $fileName = '../sdk/WxpayAPI/wechat_token.txt';
        $token_data = file_get_contents($fileName);
        $time = 7200;
        if (!empty($token_data)) {
            $token_data = json_decode($token_data, true);
            $time = time() - $token_data['time'];
        }
        if ($time > 3600) {
            $token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
            $token_res = $this->https_request($token_url);
            $token_res = json_decode($token_res, true);
            $token = $token_res['access_token'];
            $date = array(
                'time' => time(),
                'token' => $token
            );
            $res = file_put_contents($fileName, json_encode($date));
        } else {
            $token = $token_data['token'];
        }
        $name = '';
        $order_detail = Db::table('eb_order_detail')->where('order_id', $data['id'])->select()->toArray();
        foreach ($order_detail as $key => &$value) {
            $value1 = Db::table('eb_goods')->where('id', $value['goods_id'])->find();
            if ($value1['name']) {
                $name .= $value1['name'] . ' ';
            }
        }
        $user = Db::table('eb_user')->where('id', $user_id)->find();
        $store = Db::table('eb_store')->where('id', $data['store_id'])->find();
        $dats = [
            "touser" => $user['openid'], //对方的openid，前一步获取
            "template_id" => "FeHbICOGef84PEWXFkIerrFctLciWFbV2QEycFGab78", //模板id
            "data" => [
                "first" => [
                    "value" => "尊敬的骑手---".$user['name']."---， 您好！，您接的单已被用户消息订单，如有疑问请致电商家！", //自定义参数
                    "color" => '#D0AEF4'//自定义颜色
                ],
                "order_id" => [
                    "value" => $data['order_no'].'----取货码：'.$data['code'], //自定义参数
                    "color" => '#2E2E2E'//自定义颜色
                ],
                "package_id" => [
                    "value" => $data['order_no'], //自定义参数
                    "color" => '#173177'//自定义颜色
                ],
                "remark" => [
                    "value" => "如有疑问，请联系:-----" . $store['shop_name'] . '----,联系电话：' . $store['bank_phone'], //自定义参数
                    "color" => '#336600'//自定义颜色
                ],
            ]
        ];
        $msgurl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $token; // 发送模板消息接口
        $data = json_encode($dats, JSON_UNESCAPED_UNICODE);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $msgurl);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
    //随机字符串
    public function createNonceStr($length = 16)
    {
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $str = "";
        for ($i = 0; $i < $length; $i++) {
            $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
        }
        return $str;
    }

    // 模拟 http 请求
    public function https_request($url, $data = null)
    {
        // curl 初始化
        $curl = curl_init();
        // curl 设置
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        // 判断 $data get  or post
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        // 执行
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
    /**判断用户是否关注
     * @param Request $request
     * @return \think\response\Json
     */
    public function is_subscribe($openid)
    {
        require_once '../sdk/WxpayAPI/lib/WxPay.Config.php';
        $appid = \WxPayConfig::APPID;
        $secret = \WxPayConfig::APPSECRET;
        //获取token
        $fileName = '../sdk/WxpayAPI/wechat_token.txt';
        $token_data = file_get_contents($fileName);
        $time = 7200;
        if (!empty($token_data)) {
            $token_data = json_decode($token_data, true);
            $time = time() - $token_data['time'];
        }
        if ($time > 3600) {
            $token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
            $token_res = $this->https_request($token_url);
            $token_res = json_decode($token_res, true);
            $token = $token_res['access_token'];
            $date = array(
                'time' => time(),
                'token' => $token
            );
            $res = file_put_contents($fileName, json_encode($date));
        } else {
            $token = $token_data['token'];
        }
        $subscribe_msg = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$token&openid=$openid";
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $subscribe_msg);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
}
